#include<stdio.h>
#include<string.h>

int VioKMP(char* s,char* k)//暴力kmp,返回匹配的起始位置,无匹配返回-1
{
	if (!s && !k)
	{
		return -1;
	}

	int slen = strlen(s);
	int klen = strlen(k);

	for (int i = 0; i < slen; ++i)
	{
		int j = 0;
		if (s[i] == k[j])
		{
			int t = i;
			int flag = 1;
			for (j = 0; j < klen && t<slen; ++j,++t)
			{
				if (s[t] != k[j])
				{
					i = t;
					flag = 0;
					break;
				}
			}
			if (flag)
			{
				return i;
			}
		}
	}

	return -1;
}

int main()
{
	char* s = "aacgsxgasaacgxacgxggccctttaaaacgxascgxsgsgcccttt";
	char* k = "acgxg";
	int kmp = VioKMP(s, k);
	int slen = strlen(s);
	int klen = strlen(k);
	for (int i = 0; i < slen; ++i)
	{
		if (i == kmp || i == kmp + klen)
		{
			printf(" | ");
		}
		printf("%c", s[i]);
	}
    printf("\n");
	return 0;
}
